//package com.system.gateway.filter;
//
//import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
//import com.system.common.util.SYS;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.ServletServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.net.URI;
//import java.net.URL;
//import java.nio.charset.StandardCharsets;
//import java.util.Arrays;
//import java.util.List;
//
//public class GatewayGlobalFilter implements GlobalFilter, Ordered {
//
//    private static final List<String> ALLOWED_PATHS =
//            Arrays.asList("/login/dologin","/login/captcha");
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        ServerHttpRequest request = exchange.getRequest();
//        URI uri = request.getURI();
//        String path = uri.getPath();
//        System.out.println("path:"+path);
//        if (ALLOWED_PATHS.contains(path)) {
//            return chain.filter(exchange);
//        }
//        //验证有没有登录
//        //获取token
//
//        String token = request.getHeaders().getFirst(SYS.TOKEN_AUTHORIATION);
//        //判断token是否为空，还要判断Token是否有效，如果认证模块，在此通过Dubbo服务获取token是否有效
//        if (token == null) {
//
//            return exchange.getResponse().setComplete();
//        }
//        //验证token通过放行
//        return chain.filter(exchange);
//    }
//
//
//    private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) {
//
//        ServerHttpResponse response = exchange.getResponse();
//        response.setStatusCode(HttpStatus.UNAUTHORIZED);
//        response.getHeaders().add("Content-Type", "application/json");
//        return response.writeWith(Mono.just(response.bufferFactory()
//                .wrap(new JsonObject().toString().getBytes(StandardCharsets.UTF_8))));
//    }
//
//    @Override
//    public int getOrder() {
//        return 0;
//    }
//}
